import api from './api.js'
import { dateFormat, getQuery } from './utils.js'

function render($el, data) {
  let html = ''
  html += `
    <h2>${data.title}</h2>
    <h6>${data.author}</h6>
    <h6>${dateFormat(data.createtime)}</h6>
    <hr>
    <p>${data.content}</p>
  `
  $el.innerHTML = html
}

const query = getQuery()

let result = api.getDetail(query.id)
result.then(res => {
  if (res.errno === 0) {
    let data = res.data
    console.log(data)
    render($('#detail')[0], data)
  } else {
    console.log('res.errno:', res.errno)
  }
}).catch(err => {
  console.error(err)
})